<script setup lang="ts">
import {reactive, ref} from "vue";
import {countCycleTypeNum, countDeviceNum} from "@/api";
import CountUp from "@/components/count-up";
import {ElMessage} from "element-plus"

const duration = ref(2);
const state = reactive({
  paperNumb: 0,
  canNumb: 0,
  bottleNumb: 0,
});


const getData = () => {
  countCycleTypeNum().then((res) => {
    if (res.success) {
      state.paperNumb = res.data.paperNumb;
      state.canNumb = res.data.canNumb;
      state.bottleNumb = res.data.bottleNumb;
    } else {
      ElMessage.error(res.msg)
    }
  }).catch(err => {
    ElMessage.error(err)
  });
  ;
};
getData();
</script>

<template>
  <ul class="user_Overview flex">
    <li class="user_Overview-item" style="color: #ffffff">
      <div class="user_Overview_nums paper">
      </div>
      <p>纸板
        <CountUp :endVal="state.paperNumb" :duration="duration"/>
      </p>
    </li>
    <li class="user_Overview-item" style="color: #ffffff">
      <div class="user_Overview_nums can">
      </div>
      <p>易拉罐
        <CountUp :endVal="state.canNumb" :duration="duration"/>
      </p>
    </li>
    <li class="user_Overview-item" style="color: #ffffff">
      <div class="user_Overview_nums bottle">
      </div>
      <div>
        <p>塑料瓶
          <CountUp :endVal="state.bottleNumb" :duration="duration"/>
        </p>

      </div>
    </li>
  </ul>
</template>

<style scoped lang="scss">
.left-top {
  width: 100%;
  height: 100%;
}

.user_Overview {
  padding: 20px 0;
  height: 90%;
  li {
    flex: 1;
    font-size: 16px;
    font-weight: bolder;

    p {
      text-align: center;
      height: 16px;
      font-size: 18px;
      .countup-wrap{
        font-size: 32px;
        margin-top: 20px;
      }
    }

    .user_Overview_nums {
      width: 120px;
      height: 120px;
      text-align: center;
      line-height: 100px;
      font-size: 22px;
      margin: 20px auto ;
      background-size: cover;
      background-position: center center;
      position: relative;

      &::before {
        width: 100%;
        height: 100%;
        background-size: cover;
        content: "";
        position: absolute;
        top: 0;
        left: 0;
      }

      &.bgdonghua::before {
        animation: rotating 14s linear infinite;
      }
    }


    .paper {
      &::before {
        background-image: url("@/assets/img/left_bottom_paper.png");
      }
    }

    .can {
      &::before {
        background-image: url("@/assets/img/left_bottom_can.png");
      }
    }

    .bottle {
      &::before {
        background-image: url("@/assets/img/left_bottom_bottle.png");
      }
    }
  }
}

.border {
  border-width: 0px !important;
}
</style>
